package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;


@Mapper
public interface OrderMapper {


    void addOrder(Orders orders);

    @Select("select * from orders where id = #{id}")
    Orders getOrderByNumber(String id);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);


    @Select("select id, number, status, user_id, address_book_id, order_time, checkout_time, " +
            "pay_method, pay_status, amount, remark, phone, address, user_name, consignee," +
            " cancel_reason, rejection_reason, cancel_time, estimated_delivery_time," +
            " delivery_status, delivery_time, pack_amount, tableware_number, tableware_status" +
            " from orders " +
            "where status = #{status} and #{time} > order_time")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime time);

    Page<Orders> orderPage(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);
}
